From c3d8c482531a767ee2e635b93eb0d6cd075247e8 Mon Sep 17 00:00:00 2001 From: Factiven Date: Thu, 13 Apr 2023 18:24:09 +0700 Subject: Update 3rd --- pages/anime/[...id].js | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'pages/anime/[...id].js') diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js index c2e69e1..d9ef319 100644 --- a/pages/anime/[...id].js +++ b/pages/anime/[...id].js @@ -1,5 +1,4 @@ import React, { useEffect, useState } from "react"; -import { AnimatePresence, motion as m } from "framer-motion"; import { META } from "@consumet/extensions"; import Link from "next/link"; @@ -10,6 +9,8 @@ import { closestMatch } from "closest-match"; import Content from "../../components/hero/content"; import Image from "next/image"; +import { useSession } from "next-auth/react"; + export default function Himitsu({ info, slicedDesc, @@ -27,6 +28,8 @@ export default function Himitsu({ const [Lang, setLang] = useState(true); const [showAll, setShowAll] = useState(false); + const { data: session } = useSession(); + const [lastPlayed, setLastPlayed] = useState(null); const episode = episodeList; const epi1 = episode1; @@ -70,20 +73,20 @@ export default function Himitsu({ }); }, [color]); - const handleStore = (props) => { - let existingData = JSON.parse(localStorage.getItem("recentWatch")); - if (!Array.isArray(existingData)) { - existingData = []; - } - const index = existingData.findIndex( - (item) => item.title.romaji === props.title.romaji - ); - if (index !== -1) { - existingData.splice(index, 1); - } - const updatedData = [props, ...existingData]; - localStorage.setItem("recentWatch", JSON.stringify(updatedData)); - }; + // const handleStore = (props) => { + // let existingData = JSON.parse(localStorage.getItem("recentWatch")); + // if (!Array.isArray(existingData)) { + // existingData = []; + // } + // const index = existingData.findIndex( + // (item) => item.title.romaji === props.title.romaji + // ); + // if (index !== -1) { + // existingData.splice(index, 1); + // } + // const updatedData = [props, ...existingData]; + // localStorage.setItem("recentWatch", JSON.stringify(updatedData)); + // }; if (!info) { return; @@ -96,6 +99,23 @@ export default function Himitsu({ episodeIndo = episode; } + async function handleUpdate(data) { + if (!session) return; + const res = await fetch("/api/update-user", { + method: "POST", + body: JSON.stringify({ + name: session?.user.name, + newData: { + recentWatch: data, + }, + }), + headers: { + "Content-Type": "application/json", + }, + }); + // console.log(res.status); + } + // console.log({ NEXT: subIndo }); // console.log(episodeIndo); @@ -177,7 +197,7 @@ export default function Himitsu({ - handleStore({ + handleUpdate({ title: { romaji: info.title.romaji || @@ -357,7 +377,7 @@ export default function Himitsu({ }} className="w-full shrink h-[126px] bg-secondary flex rounded-md" > -
+
{relation.id} {relation.relationType}
-
+
{relation.title.romaji}
{relation.type}
@@ -420,7 +440,7 @@ export default function Himitsu({
- handleStore({ + handleUpdate({ title: { romaji: info.title.romaji || -- cgit v1.2.3